package cn.lzx.org.service.impl;

import cn.lzx.basic.service.impl.BaseServiceImpl;
import cn.lzx.org.domain.Employee;
import cn.lzx.org.domain.Shop;
import cn.lzx.org.mapper.EmployeeMapper;
import cn.lzx.org.mapper.ShopMapper;
import cn.lzx.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 店铺service实现类
 */
@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {

    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 店铺入驻
     * @param shop
     */
    @Override
    public void saveShop(Shop shop) {
        //根据员工名字电话邮件判断是否是第一次入驻
        Employee employee = employeeMapper.findByAccount(shop.getAdmin());
        if (employee!=null){
            throw new RuntimeException("入驻失败,该用户已存在一个店铺");
        }
        //保存employee的信息 可以获取id自增长
        employeeMapper.save(shop.getAdmin());
        //保shop信息 在shop中绑定管理员的id
        shopMapper.save(shop);
        //在管理员中绑定店铺id
        employeeMapper.updateShopId(shop);
    }


}
